const http = require('http');

const postData = JSON.stringify({
  username: 'admin',
  password: '123456',
  usertype: '1',
});

const opts = {
  hostname: '127.0.0.1',
  port: 3000,
  path: '/api/v1/login',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(postData),
  },
};

const req = http.request(opts, (res) => {
  let data = '';
  res.on('data', (chunk) => (data += chunk));
  res.on('end', () => {
    console.log('STATUS', res.statusCode);
    console.log('BODY', data);
  });
});

req.on('error', (e) => {
  console.error('ERR', e.message);
});

req.write(postData);
req.end();
